﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using easysql;
using Model;
namespace Dal
{
    public class RoleMenuDal:BaseDal<RoleMenuModel>
    {
        public RoleMenuDal()
            : base("tb_roleMenu")
        {
            
        }
        public List<RoleMenuModel> Query(RoleMenuModel bean)
        {
            return PriQuery(bean);
        }

    
        public void UpdateMenuId(int roleId,string menuIds)
        {
            RoleMenuModel bean_del = new RoleMenuModel();
            bean_del.roleId = roleId;
            using (var db = dh.CreateDatabaseAndOpen())
            {
                db.BeginTransaction();
                db.Del(this.tbname, bean_del);

                foreach (var menuId in menuIds.Split(','))
                {
                    RoleMenuModel model = new RoleMenuModel();
                    model.roleId = roleId;
                    model.menuId = int.Parse(menuId);
                    db.Add<RoleMenuModel>(this.tbname, model);
                }

                db.CommitTranscation();
            }
        }
    
    }
}
